package aaaQunar;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.attilax.core;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.net.websitex;


/**
 * aaaQunar.Qunar
 * @author Administrator
 *
 */
public class Qunar {

	public static void main(String[] args) throws UnsupportedEncodingException {
		
		String f= (pathx.classPathParent_jensyegeor()
				+ "/qunar_kw.txt");
		List<String> li=filex.read2list_filtEmptyNstartSpace(f,"gbk");
		for (String kw_s : li) {
			try {
				ProcessSingle(kw_s);
			} catch (Exception e) {
				// TODO: handle exception
			}
		}
		
		
		System.out.println("--f");
	}
	
	
public Object search(Object kw)
{
	List<String> li=	ProcessSingle((String) kw);
	//List<String> li=new ArrayList<String>();
	//li.add("aa");
	//li.add("bb");
	return core.toJsonStrO88(li);
	
}
	private static List<String> ProcessSingle(String kwx)
			  {
//		 = "乌鲁木齐";
//		
//		kwx=args[0];
		List<String> li=new ArrayList<String>();
		String kw = null;
		try {
			kw = URLEncoder.encode(kwx, "utf-8");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String s = "http://dujia.qunar.com/golfz/routeList/adaptors/pcTop?isTouch=0&t=all&o=pop-desc&lm=0%2C30&fhLimit=0%2C30&q="
				+ kw
				+ "&d=%E6%A0%AA%E6%B4%B2&s=all&qs_ts=1444750954450&ti=1&tm=l01_all_hotdes_newb&sourcepage=list&qssrc=eyJ0cyI6IjE0NDQ3NTA5NTQ0NTAiLCJzcmMiOiJhbGwuZW52YiIsImFjdCI6InNlYXJjaCJ9&m=l%2Clm&displayStatus=pc&lines6To10=0";
		  String json=websitex.WebpageContent(s);

		String ft = filex.read(pathx.classPathParent_jensyegeor()
				+ "/qunar/search.json");
		JSONObject jo = JSONObject.fromObject(json);
		JSONArray ja = jo.getJSONObject("data").getJSONObject("list")
				.getJSONArray("results");
		for (Object object : ja) {
			try {
				JSONObject jo_t=(JSONObject) object;
				String tit = jo_t.getString("search_title");
				String tit2 = tit.substring(0, 30)+"...";
				System.out.println(tit2);
				li.add(tit2);
				
			} catch (Exception e) {
				// TODO: handle exception
			}
			
		}
		return li;
	}

}
